<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\api\controller;

use app\api\model\Satisfaction as SatisfactionModel;
use think\response\Json;
use cores\exception\BaseException;


class Satisfaction extends Controller
{

    /**
     * 2023年11月23日19:51:26
     * 用户前台添加满意记录，最多可以10条
     * @param $data
     * @return bool|Json
     * @throws BaseException
     * @throws \think\db\exception\DbException
     */
    public function add($data)
    {
        $userInfo=$this->getLoginUser();
        if(!$userInfo){
            $this->error = '未登录，请登录';
            return false;
        }

        $finalData["satisfaction_user"]=$userInfo["satisfaction_user"];
        $finalData["satisfaction_userphone"]=$userInfo["satisfaction_userphone"];
        $finalData["satisfaction_all"] = $data["zt"];
        $finalData["satisfaction_price"] = $data["tm"];
        $finalData["satisfaction_attitude"] = $data["td"];
        $finalData["satisfaction_chat"] = $data["gt"];
        $finalData["satisfaction_treatment"] = $data["zl"];
        $finalData["satisfaction_xiaodu"] = $data["xd"];
        $finalData["satisfaction_weisheng"] = $data["ws"];
        $finalData["satisfaction_time"] = $data["dh"];

        $model = new SatisfactionModel();
        $alreadyCount=$model->getCount($finalData["satisfaction_userphone"]);
        if($alreadyCount>10){
            return $this->renderError($model->getError() ?: '您已经反馈了多条记录');
        }

        if (!$model->add($finalData)) {
            return $this->renderError($model->getError() ?: '添加失败');
        }
        return $this->renderSuccess("添加成功");
    }
}
